unit FormClassTree;

interface

uses
  Windows, Messages, SysUtils, DB, ADODB, StdCtrls, Buttons, Mask, DBCtrls,
  Controls, ExtCtrls, Classes, fcTreeView, Graphics, Forms, Dialogs,
  ComCtrls, ImgList, FormClass, ActnList, StdActns, XPMan;

type
  TfmFormClassTree = class(TfmFormClass)
  private
    Node, NodeIlk: TfcTreeNode;
    DNode: array[0..4] of TfcTreeNode;
    DKod, EKod: array[0..4] of string;
    ItemString: string;
    { Private declarations }
  public
    { Public declarations }
    procedure PrepareTreeView(dxTree: TfcTreeView; gItemString: string; gItemAdi: string;
      ImageIndex: Smallint = -1; gEskiKod: string = ''; gCheck: Boolean = True; gRadio: Boolean = False;
      SelectedImageIndex: Smallint = -1; StateImageIndex: Smallint = -1; Visible: Boolean = True); virtual;

  end;

var
  fmFormClassTree: TfmFormClassTree;

implementation

uses UnitOrtak, UnitTeknik;
{$R *.dfm}

procedure TfmFormClassTree.PrepareTreeView(dxTree: TfcTreeView; gItemString: string; gItemAdi: string;
  ImageIndex: Smallint = -1; gEskiKod: string = ''; gCheck: Boolean = True; gRadio: Boolean = False;
  SelectedImageIndex: Smallint = -1; StateImageIndex: Smallint = -1; Visible: Boolean = True);
var
  i: Integer;
  gItemKod1: string;
  gItemKod2: string;
  gItemKod3: string;
  gItemKod4: string;
  gItemKod5: string;

  function AddChilds(Node: TfcTreeNode; StringData: string; Etiket: string): TfcTreeNode;
  var
    N: TfcTreeNode;
  begin
    N := dxTree.Items.AddChild(Node, Etiket);
    StringData := KarekterCikar(StringData, '_');

    N.SelectedIndex := SelectedImageIndex;
    N.ImageIndex := ImageIndex;
    N.StateIndex := StateImageIndex;

    if gCheck then
    begin
      N.StateIndex := -1;
      N.CheckboxType := tvctCheckbox;
      N.Checked := False;
    end;

    N.StringData := StringData;
    N.StringData2 := gEskiKod; //gItemAdi;
    if gRadio then
    begin
      N.StateIndex := -1;
      N.CheckboxType := tvctRadioGroup;
      N.Checked := False;
    end;
    Result := N;
  end;

begin
  if (SelectedImageIndex < 0) then
    SelectedImageIndex := ImageIndex;

  dxTree.OnToggleCheckbox := nil;

  gItemKod1 := Copy(Trim(gItemString), 4, 2);
  gItemKod2 := Copy(Trim(gItemString), 7, 2);
  gItemKod3 := Copy(Trim(gItemString), 10, 2);
  gItemKod4 := Copy(Trim(gItemString), 13, 2);
  gItemKod5 := Copy(Trim(gItemString), 16, 2);

  DKod[0] := gItemKod1;
  DKod[1] := gItemKod2;
  DKod[2] := gItemKod3;
  DKod[3] := gItemKod4;
  DKod[4] := gItemKod5;
  ItemString := gItemString;

  if CharCount('_', gItemString) < 1 then
    NodeIlk := AddChilds(nil, gItemString, gItemAdi)
  else
  begin
    for i := Low(DKod) to High(DKod) do
    begin
      if DKod[i] <> EKod[i] then
        Break;
    end;

    case i of
      0:
        begin
          Node := AddChilds(NodeIlk, ItemString, gItemAdi);
          DNode[0] := Node;
        end;
      1:
        begin
          Node := AddChilds(DNode[0], ItemString, gItemAdi);
          DNode[1] := Node;
        end;
      2:
        begin
          Node := AddChilds(DNode[1], ItemString, gItemAdi);
          DNode[2] := Node;
        end;
      3:
        begin
          Node := AddChilds(DNode[2], ItemString, gItemAdi);
          DNode[3] := Node;
        end;
      4:
        begin
          Node := AddChilds(DNode[3], ItemString, gItemAdi);
          DNode[4] := Node;
        end;
    end;
  end;

  EKod[0] := gItemKod1;
  EKod[1] := gItemKod2;
  EKod[2] := gItemKod3;
  EKod[3] := gItemKod4;
  EKod[4] := gItemKod5;
end;

end.

